package models

import (
	"time"

	"gorm.io/gorm"
)

type GoodsDailyReport struct {
	ID                  string     `gorm:"primaryKey;column:id;type:varchar(20);not null" json:"id"`
	MerchantID          *string    `gorm:"index:idx_createdDate_merchantID,priority:2;column:merchant_id;type:bigint;not null;default:0;comment:商户ID" json:"merchant_id"`
	MerchantName        *string    `gorm:"-" json:"merchant_name"`
	RobotName           *string    `gorm:"uniqueIndex:idx_createdDate_robotName_goodsID,priority:2;column:robot_name;type:varchar(50);not null;default:'';comment:机器名称" json:"robot_name"`
	CreatedDate         *time.Time `gorm:"uniqueIndex:idx_createdDate_robotName_goodsID,priority:1;index:idx_createdDate_goodsName,priority:1;index:idx_createdDate_merchantID,priority:1;column:created_date;type:date;comment:日期" json:"-"`
	CreatedDateFormated *int64     `gorm:"-" json:"created_date"`
	GoodsID             *string    `gorm:"uniqueIndex:idx_createdDate_robotName_goodsID,priority:3;column:goods_id;type:varchar(50);not null;default:'';comment:商品id" json:"goods_id"`
	GoodsName           *string    `gorm:"index:idx_createdDate_goodsName,priority:2;column:goods_name;type:varchar(50);not null;default:'';comment:商品名称" json:"goods_name"`
	ProvinceID          *string    `gorm:"column:province_id;type:bigint;not null;default:0;comment:省份ID" json:"-"`
	CityID              *string    `gorm:"column:city_id;type:bigint;not null;default:0;comment:城市ID" json:"-"`
	LocationID          *string    `gorm:"column:location_id;type:bigint;not null;default:0;comment:位置ID" json:"-"`
	Province            *string    `gorm:"-" json:"province"`
	City                *string    `gorm:"-" json:"city"`
	Location            *string    `gorm:"-" json:"location"`
	GMV                 *float64   `gorm:"column:gmv;type:decimal(10,2);not null;default:0.00;comment:GMV" json:"gmv,omitempty"`
	PaymentAmount       *float64   `gorm:"column:payment_amount;type:decimal(10,2);not null;default:0.00;comment:实付金额" json:"payment_amount,omitempty"`
	TransactionAmount   *float64   `gorm:"column:transaction_amount;type:decimal(10,2);not null;default:0.00;comment:交易金额" json:"transaction_amount,omitempty"`
	DiscountAmount      *float64   `gorm:"column:discount_amount;type:decimal(10,2);not null;default:0.00;comment:优惠金额" json:"discount_amount,omitempty"`
	RefundAmount        *float64   `gorm:"column:refund_amount;type:decimal(10,2);not null;default:0.00;comment:退款金额" json:"refund_amount,omitempty"`
	GiveAmount          *float64   `gorm:"column:give_amount;type:decimal(10,2);not null;default:0.00;comment:抽奖赠送" json:"give_amount,omitempty"`
	TotalOrder          *int64     `gorm:"column:total_order;type:int(10);not null;default:0;comment:创单笔数" json:"total_order,omitempty"`
	TotalPaidOrder      *int64     `gorm:"column:total_paid_order;type:int(10);not null;default:0;comment:支付笔数" json:"total_paid_order,omitempty"`
	TotalNotPaidOrder   *int64     `gorm:"column:total_not_paid_order;type:int(10);not null;default:0;comment:未支付笔数" json:"total_not_paid_order,omitempty"`
	TotalRefundOrder    *int64     `gorm:"column:total_refund_order;type:int(10);not null;default:0;comment:退款笔数" json:"total_refund_order,omitempty"`
	TotalPaidUser       *int64     `gorm:"column:total_paid_user;type:int(10);not null;default:0;comment:支付人数" json:"total_paid_user,omitempty"`
	TotalGoodsClick     *int64     `gorm:"column:total_goods_click;type:int(10);not null;default:0;comment:商品点击量" json:"total_goods_click,omitempty"`
	PaidRatio           *float64   `gorm:"-" json:"paid_ratio"`         // 支付率
	CreateOrderRatio    *float64   `gorm:"-" json:"create_order_ratio"` // 创单率
	RefundRatio         *float64   `gorm:"-" json:"refund_ratio"`       // 退款率
	CreatedAt           int64      `gorm:"column:created_at;autoCreateTime;type:int;size:64;comment:创建时间" json:"created_at"`
	UpdatedAt           int64      `gorm:"column:updated_at;autoUpdateTime;type:int;size:64;comment:更新时间" json:"updated_at"`
}

func (m *GoodsDailyReport) AfterFind(tx *gorm.DB) (err error) {
	if m.CreatedDate != nil {
		if !time.Time(*m.CreatedDate).IsZero() {
			createdDate := m.CreatedDate.Unix()
			m.CreatedDateFormated = &createdDate
		}
	}
	return
}
func (m GoodsDailyReport) TableName() string {
	return "goods_daily_report"
}

// 模式自动注册
func init() {
	Models = append(Models, &GoodsDailyReport{})
}
